<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>猜数字VUE版</title>
</head>
<body>
<div>
    <input type="text" placeholder="请输入1-100之间的整数" v-model="n1">
    <input type="button" value="猜一猜" @click="f()">
    <h3>结果：{{result}}</h3>
</div>

<script src="js/vue.min.js"></script>

<script>
    let x = parseInt(Math.random() * 100) + 1;
    console.log(x);
    let count = 0;
    let v = new Vue({
        el: "body>div",
        data: {
            n1: "", result: ""
        },
        methods: {
            f() {
                if (isNaN(v.n1)) {
                    v.result = "输入错误！";
                    return;
                }
                count++;
                if (v.n1 > x) {
                    v.result = "猜大了!";
                } else if (v.n1 < x) {
                    v.result = "猜小了!"
                } else {
                    v.result = "恭喜你第" + count + "次猜对了!"
                }
            }
        }
    })
</script>

</body>
</html>